<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>新建方案newPricePlan</title>
	</head>
	<link rel="stylesheet" href="../css/common.css" />
	<style>
		select{
			border:none;
			outline:none;
			width:100%;
			height:100%;
			padding-left:20%;
		}
		input[type=text]{
			border:none;
			outline:none;
			width:90%;
			height:100%;
			padding-left:10px;
		}
		input[type=radio]{
			position:relative;
			top:5px;
			left:-5px;
		}
		#date table td,#limit table td{
			height:42px;
		}
		
		.width{
			width:324px;
		}
		.width2{
			width:129px;
		}
		#box{
			width:800px;
			margin:0 auto;
		}
		#box .title{
			height:40px;
			line-height:40px;			
		}
		#box .background{
			background:#f1f1f1;
			width:70px;					
		}
		#box .background1{
			background:#f1f1f1;
			width:33%;	
		}
		#box .background2{
			background:#f1f1f1;
		}
		#box .star{
			font-size:18px;
			color:Red;	
			position:relative;
			top:5px;			
		}
		#box .title>span{
			display:inline-block;
			width:4px;
			height:13px;
			background:#00a899;
			margin-right:8px;
			transform:translateY(2px);
		}
		#box table{
			width:100%;
		}
		#box table td{
			border:1px solid #e7e7e7;
		}
		.priceTable tr{
			height:27px;
		}
		.priceTable tr:nth-of-type(1){
			height:32px;
		}
		.priceTable input[type=text]{
			text-align:center;
			border:none;
			outline:none;
			width:100%;
			height:100%;
			padding:0;
		}
		#limit input[type=text]{
			text-align:center;
		}
		#btn{
			text-align:center;
			margin-top:60px;
		}
		#btn button{
			width:116px;
			height:36px;
			color:white;
			cursor:pointer;
			border-radius:1px;
			border:none;
			background:#00aa98;
		}
		#btn .cancel{
			background:#909090;
		}
		
		.zuoweishu input[type=text],.tuipiaofei input[type=text],.gaiqifei input[type=text]{
			border:1px solid #e2e2e4;
			height:22px;
			width:120px;
		}
	</style>
	<body ng-app="myApp" ng-controller="ctrl1">
		<div id="box">
			<div id="date">
				<p class="title"><span></span><b>适用日期</b></p>
				<table class="dateTable">
					<tr>
						<td class="background">方案编号</td>
						<td class="background"></td>
						<td class="background">方案类型</td>
						<td class="width2">
							<select ng-model="data.type">
								<option value="QW">切位</option>
								<option value="SK">散客</option>
							</select>
						</td>
						<td class="background">适用舱位</td>
						<td class="width2">
							<select ng-model="data.cabin">
								<option value="Y">经济舱</option>
								<option value="F">头等舱</option>
								<option value="C">商务舱</option>
							</select>
						</td>
						<td class="background">货币类型</td>
						<td class="width2">
							<select ng-model="data.currency">
								<option value="CNY">人民币</option>
								<option value="MYR">马币</option>
							</select>
						</td>
					</tr>
					<tr>
						<td class="background">创建人<span class="star">*</span></td>
						<td class="width2" id="creator">${session.name}</td>
						<td class="background">开始日期<span class="star">*</span></td>
						<td class="width2"><input ng-model="data.startDate" type="text" class='datespicker' onClick="WdatePicker({onpicked: function(){$(this).trigger('change')}})"/></td>
						<td class="background">结束日期<span class="star">*</span></td>
						<td class="width2"><input ng-model="data.endDate" type="text" class='datespicker' onClick="WdatePicker({onpicked: function(){$(this).trigger('change')}})"/></td>
						<td class="background"></td>
						<td class="width2"></td>
					</tr>
				</table>
			</div>
			<div id="limit">
				<p class="title"><span></span><b>限制条件</b></p>
	<!-- 散客信息 -->
				<table ng-show="!qiewei" class="sankeTable">
					<tr>
						<td class="background">退票费</td>
						<td class="tuipiaofei width">
							<span style="margin:0 5px 0 15px;"><input ng-change = "fn(free)" ng-model="free.refundFee_S" value="noAllow" type="radio" name="refundFee_S"/> 不允许</span>
							<span><input ng-change = "fn(free)" ng-model="free.refundFee_S" value="allow" type="radio" name="refundFee_S"> 允许</span>
							<span style="margin:0 0 0 20px;"><input ng-model="freeCount.refundFee_S" ng-readonly="readonly.refundFee_S" type="text"></span>
						</td>
						<td class="background" rowspan="2">其他备注</td>
						<td rowspan="2"><input ng-model="remark_S" type="text"/></td>							
					</tr>
					<tr>
						<td class="background width">改期费</td>
						<td class="gaiqifei">
							<span style="margin:0 5px 0 15px;"><input ng-change = "fn(free)" ng-model="free.revaFee_S" value="noAllow" type="radio" name="revaFee_S"/> 不允许</span>
							<span><input ng-change = "fn(free)" ng-model="free.revaFee_S" value="allow" type="radio" name="revaFee_S"/> 允许</span>
							<span style="margin:0 0 0 20px;"><input ng-model="freeCount.revaFee_S" ng-readonly="readonly.revaFee_S" type="text"/></span>
						</td>												
					</tr>
				</table>
	<!-- 切位信息 -->
				<table ng-show="qiewei" class="qieweiTable">
					<tr>
						<td class="background">座位数</td>
						<td class="width background2 zuoweishu">
							<input ng-model="data.seatMin" type="text"/> — <input ng-model="data.seatMax" type="text"/>
						</td>
						<td class="background">出票率</td>
						<td colspan="3"><input ng-model="data.ticketRate" type="text"/></td>						
					</tr>
					<tr>
						<td class="background">退票费</td>
						<td class="width tuipiaofei">
							<span style="margin:0 5px 0 15px;"><input ng-change = "fn(free)" ng-model="free.refundFee_Q" value="noAllow" type="radio" name="refundFee_Q"/> 不允许</span>
							<span><input ng-change = "fn(free)" ng-model="free.refundFee_Q" value="allow" type="radio" name="refundFee_Q"/> 允许</span>
							<span style="margin:0 0 0 20px;"><input ng-readonly="readonly.refundFee_Q" ng-model="freeCount.refundFee_Q" type="text"/></span>
						</td>
						<td class="background">票损率</td>
						<td><input ng-model="data.ticketLossRate" type="text"/></td>
						<td class="background">票损</td>
						<td><input ng-model="data.ticketLoss" type="text"/></td>
					</tr>
					<tr>
						<td class="background">改期费</td>
						<td class="width gaiqifei">
							<span style="margin:0 5px 0 15px;"><input ng-change = "fn(free)" ng-model="free.revaFee_Q" value="noAllow" type="radio" name="revaFee_Q"/> 不允许</span>
							<span><input ng-change = "fn(free)" ng-model="free.revaFee_Q" value="allow" type="radio" name="revaFee_Q"/> 允许</span>
							<span style="margin:0 0 0 20px;"><input ng-readonly="readonly.revaFee_Q" ng-model="freeCount.revaFee_Q" type="text"/></span>
						</td>
						<td class="background">其他备注</td>
						<td colspan="3"><input ng-model="remark_Q" type="text"/></td>
					</tr>
				</table>
			</div>
			<div id="price">
				<p class="title"><span></span><b>价格体系</b></p>
				<table class="priceTable">
					<tr>
						<td class="background1">旅客/舱位</td>
						<td class="background1">价格调整<i class="star">*</i></td>
						<td class="background1">税金<i class="star">*</i></td>
					</tr>
					<tr>
						<td>成人</td>
						<td><input ng-model="data.adultAdjustment" type="text"/></td>
						<td><input ng-model="data.adultTFC" type="text"/></td>
					</tr>
					<tr>
						<td>儿童(2-12)</td>
						<td><input ng-model="data.childAdjustment" type="text"/></td>
						<td><input ng-model="data.childTFC" type="text"/></td>
					</tr>
					<tr>
						<td>婴儿(0-2)</td>
						<td><input ng-model="data.infantAdjustment" type="text"/></td>
						<td><input ng-model="data.infantTFC" type="text"/></td>
					</tr>
				</table>
			</div>
			<div id="btn">
				<button ng-click="sure()">确认</button>
				<button ng-click="close()" class="cancel">取消</button>
			</div>
		</div>					
	</body>
		<script type="text/javascript" src="../js/jquery-1.12.4.js" ></script>
		<script type="text/javascript" src="../layer-v2.4/layer/layer.js" ></script>
			<!-- 引入my97日期时间控件 -->
		<script type="text/javascript" src="../js/My97DatePicker/WdatePicker.js" charset="utf-8"></script>	
		<script type="text/javascript" src="../js/angular.min.js" ></script>
		<script type="text/javascript" src="../js/common.js" ></script>
		<script>
			angular.module("myApp",[])
			.controller("ctrl1",function($scope,$http){	
				$scope.qiewei = true;      //默认显示切位的限制条件	
				//默认禁止输入退票费改期费
				$scope.readonly = {
					refundFee_S:true,
					revaFee_S:true,
					refundFee_Q:true,
					revaFee_Q:true
				}
				//默认选中不允许
				$scope.free = {
					refundFee_S:"noAllow",
					revaFee_S:"noAllow",
					refundFee_Q:"noAllow",		
					revaFee_Q:"noAllow"
				}
				//费用的默认值
				$scope.freeCount = {
					refundFee_S:null,
					revaFee_S:null,
					refundFee_Q:null,
					revaFee_Q:null	
				}
				//允许与不允许的操作
				$scope.fn = function(free){					
					for(let i in free){
						if(free[i]=="allow"){
							$scope.readonly[i] = false;
						}
						if(free[i]=="noAllow"){
							$scope.readonly[i] = true;
							$scope.freeCount[i] = null;
						}
					}
				}
				
		
				$scope.$watch("data.type",function(newVal,oldVal){
					if(newVal=="QW") $scope.qiewei = true;
					if(newVal=="SK") $scope.qiewei = false;				
				})		
				
				$scope.data = {
					type:"QW",                       //默认方案类型
					cabin:"Y",                       //默认舱位类型
					currency:"CNY",                  //默认货币类型
					startDate:null,                  //开始日期
					endDate:null,                    //结束日期
					creator:$("#creator").text(),    //创建人
					seatMin:null,                    //最小座位数
					seatMax:null,                    //最大座位数
					ticketRate:null,                 //出票率
					ticketLoss:null,                 //票损
					ticketLossRate:null,             //票损率					
					adultAdjustment:null,            //成人价格调整
					adultTFC:null,					 //成人税金
					childAdjustment:null,			 //儿童价格调整
					childTFC:null,					 //儿童税金
					infantAdjustment:null,			 //婴儿价格调整
					infantTFC:null,					 //婴儿税金
					remark:null,                     //备注
					refundFee:null,                  //退票费
					revaFee:null                     //改期费
				}
				
				$scope.sure = function(){
					if($scope.data.type=="QW") QW();
					if($scope.data.type=="SK") SK();					
					checkOut();
					submit();
				}
				$scope.close = function(){
					 closeWin();
				}
				
				
				
				//数据验证
				function checkOut(){
					inputCheckoutFun.Empty($scope.data.startDate,"出发日期","不能为空");
					inputCheckoutFun.Empty($scope.data.endDate,"结束日期","不能为空");
					if($scope.data.startDate>$scope.data.endDate){
						layer.msg("开始日期不能大于结束日期",{icon: 2,time:1000})
						throw "开始日期不能大于结束日期"; 
					}
					if($scope.data.type=="QW"){
						inputCheckoutFun.seatCount.normal($scope.data.seatMin,"最小座位数","不能为空,且为整数");
						inputCheckoutFun.seatCount.normal($scope.data.seatMax,"最大座位数","不能为空,且为整数");
						inputCheckoutFun.rate.normal($scope.data.ticketRate,"出票率","不能为空,最多保留两位小数");
						inputCheckoutFun.rate.normal($scope.data.ticketLossRate,"票损率","不能为空,最多保留两位小数");
						inputCheckoutFun.price.normal($scope.data.ticketLoss,"票损","不能为空,最多保留两位小数");
						if($scope.data.seatMin-0>$scope.data.seatMax-0){
							layer.msg("最小座位数不能大于最大座位数",{icon:2,time:1000})
							throw "最小座位数不能大于最大座位数";
						}
						if($scope.data.ticketLossRate-0>$scope.data.ticketRate-0){
							layer.msg("票损率不能大于出票率",{icon:2,time:1000})
							throw "票损率不能大于出票率";
						}
					}					
					inputCheckoutFun.price.normal($scope.data.adultAdjustment,"成人价格调整","不能为空,最多保留俩位小数");
					inputCheckoutFun.price.normal($scope.data.adultTFC,"成人税金","不能为空");
					inputCheckoutFun.price.normal($scope.data.childAdjustment,"儿童价格调整","不能为空,最多保留俩位小数");
					inputCheckoutFun.price.normal($scope.data.childTFC,"儿童税金","不能为空");
					inputCheckoutFun.price.normal($scope.data.infantAdjustment,"婴儿价格调整","不能为空,最多保留俩位小数");
					inputCheckoutFun.price.normal($scope.data.infantTFC,"婴儿税金","不能为空");
					
				}
				//将数据发送至后端
				function submit(){
					layer.load(3,{shadeClose:true});//加载层；
					$http({
						url:"../fareplan/createFarePlan?temp="+Math.random(),
						method:'post',
						data:$scope.data
					}).success(function(data,header,config,status){
						layer.closeAll();				
						if(data.status=="1001"){				
							layer.msg("创建成功",{icon:1,time:"1000"},function(){
								closeWin();
							})				
						}else{
							layer.alert(data)
						}
						//响应成功
					}).error(function(data,header,config,status){
						layer.closeAll();	
						console.log(data)
						layer.alert("请求失败，请检查网络连接")
						//处理响应失败
					});
				}
				//确定散客或切位
				function QW(){					
					$scope.data.remark = $scope.remark_Q;
					$scope.data.refundFee = $scope.freeCount.refundFee_Q;
					$scope.data.revaFee = $scope.freeCount.revaFee_Q;
				}
				function SK(){					
					$scope.data.remark = $scope.remark_S;
					$scope.data.refundFee = $scope.freeCount.refundFee_S;
					$scope.data.revaFee = $scope.freeCount.revaFee_S;
				}
				
			})
		
		</script>		
</html>
